<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="./vue.js"></script>
</head>

<body>
  <div id="app">
    <cpn :number2="num2" :number1="num1" @num1change="num1change" @num2change="num2change"></cpn>
  </div>
  <template id="cpn">
    <div>
      <h2>props:{{number1}}</h2>
      <h2>data:{{dnumber1}}</h2>
      <!-- <input type="text" v-model="dnumber1"> -->
      <!-- <input type="text" v-model="number1">  -->
      <input type="text" :value="dnumber1" @input="num1Input">
      <!-- 我们这里需要vue中的数值随我们输入的数值而变换，并且更改组件中的值 
      虽然我们此时是可以通过number1的双向绑定可以操作这个值，但是vue会报错，是不推荐用
      子组件来对他进行修改的-->
      <!-- 要使用data或者computed的方法来修改这个值 -->
      <h2>props:{{number2}}</h2>
      <h2>data:{{dnumber2}}</h2>
      <input type="text" :value="dnumber2" @input="num2Input">
      <!-- <input type="text" v-model="dnumber2"> -->
    </div>
  </template>
  <script>
    var vm = new Vue({
      el: '#app',
      data: {
        num1: 0,
        num2: 1
      },
      methods: {
        num1change(value) {
          this.num1 = parseInt(value)
        },
        num2change(value) {
          this.num2 = parseInt(value)
        }
      },
      components: {
        cpn: {
          template: '#cpn',
          props: {
            number1: Number,
            number2: Number
          },
          data() {
            return {
              dnumber1: this.number1,
              dnumber2: this.number2
            }
          },
          methods: {
            num1Input() {
              this.dnumber1 = event.target.value
              this.$emit('num1change', this.dnumber1)
            },
            num2Input() {
              this.dnumber2 = event.target.value
              this.$emit('num2change', this.dnumber2)
            }
          }
        }
      }
    })
  </script>
</body>

</html>